package com.zzyq.pc.web.submit.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zzyq.pc.common.plugin.db.PageView;
import com.zzyq.pc.web.submit.mapper.SubmitMapper;
import com.zzyq.pc.web.submit.model.Submit;
import com.zzyq.pc.web.submit.service.ISubmitService;

@Service
public class SubmitServiceImpl implements ISubmitService {
    @Autowired
    SubmitMapper submitMapper;

    @Override
    public boolean post(Submit submit) {
        return submitMapper.insert(submit) > 0;
    }

    @Override
    public boolean review(Submit submit) {
        return submitMapper.update(submit) > 0;
    }

    @Override
    public List<Submit> selectAsList(PageView pageView, Submit submit, Integer companyId) {
        Map<String, Object> map = new HashMap<>();
        if (pageView != null) {
            map.put("paging", pageView);
        }
        map.put("submitId", submit.getSubmitId());
        map.put("postUserId", submit.getPostUserId());
        map.put("receiveUserId", submit.getReceiveUserId());
        map.put("companyId", companyId);
        return submitMapper.selectAsList(map);
    }

    @Override
    public List<Submit> selectUntreatedByUserId(Integer userId) {
        if (userId == null) {
            return new ArrayList<>();
        }
        return submitMapper.selectUntreatedByUserId(userId);
    }

}
